package com.mmm.user.controller;

import com.mmm.common.vo.SuccessVo;
import com.mmm.user.entity.Delivery;
import com.mmm.user.service.DeliveryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Delivery)表控制层
 *
 * @author One
 * @since 2022-02-27 10:58:04
 */
@RestController
@RequestMapping("delivery")
public class DeliveryController {
    /**
     * 服务对象
     */
    @Resource
    private DeliveryService deliveryService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public SuccessVo<Delivery> selectOne(@PathVariable Long id) {
        return new SuccessVo<>(this.deliveryService.queryById(id));
    }

    @PutMapping("/put")
    public SuccessVo<Delivery> insert(@RequestBody Delivery delivery) {
        return new SuccessVo<>(1,deliveryService.insert(delivery));
    }

    @DeleteMapping("/delete/{id}")
    public SuccessVo<Boolean> delete(@PathVariable Long id) {
        return new SuccessVo<>(2,deliveryService.deleteById(id));
    }

    @PostMapping("/update")
    public SuccessVo<Delivery> update(@RequestBody Delivery delivery){
        return new SuccessVo<>(3,deliveryService.update(delivery));
    }

    @GetMapping("/list/{id}")
    public SuccessVo<java.util.List<Delivery>> list(@PathVariable Long id){
        return  new SuccessVo<>(deliveryService.getAll(id));
    }

    @GetMapping("/list")
    public SuccessVo<com.mmm.common.vo.Paging<Delivery>> page(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size){
        return new SuccessVo<>(deliveryService.page(page,size));
    }
    //获取用户选择大学的快递点
    @GetMapping("/list/byUser")
    public SuccessVo<com.mmm.common.vo.Paging<Delivery>> pageByUser(@RequestHeader("Authorization") String authorization,@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size){
        return new SuccessVo<>(deliveryService.pageByUser(authorization,page,size));
    }


}